home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / shell / ncd-0.000 / ncd-0 / ncd-0.9.8 / disp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-06  |  7.0 KB  |  365 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ncurses.h>
  4.  
  5. #include "ncd.h"
  6.  
  7. /*************************************************************************/
  8.  
  9. void paintLayout(void)
  10. {
  11.     char *title = "Ninux Change Directory";
  12.     size_t len;
  13.     
  14.     _refCurrent = _refRest = _refCurDir = _refSearch = 1;
  15.  
  16.     attrset(getColorMode(0));
  17.     border(0, 0, 0, 0, 0, 0, 0, 0);
  18.  
  19.     mvaddch(_lines - 4, 0, ACS_LTEE);
  20.     hline(ACS_HLINE, COLS - 2);
  21.     mvaddch(_lines - 4, COLS - 1, ACS_RTEE);
  22.  
  23.     mvaddstr(_lines - 2, 2, "Search:");
  24.     mvaddstr(_lines - 2, COLS - 13, "HELP=Ctrl+i");
  25.  
  26.     attrset(getColorMode(1));
  27.     len = strlen(title);
  28.     if (len > COLS - 4)
  29.         len = COLS - 4;
  30.     mvaddch(0, (COLS - len) / 2 - 1, ' ');
  31.     waddnstr(stdscr, title, len);
  32.     addch(' ');
  33.     
  34.  
  35. }
  36.  
  37. /*************************************************************************/
  38.  
  39. char *truncString(char *s, int maxlen)
  40. {
  41.     int len;
  42.  
  43.     len = strlen(s);
  44.  
  45.     if (len > maxlen) {
  46.         s += (len - maxlen);
  47.         s[0] = s[1] = s[2] = '.';
  48.     }
  49.  
  50.     return s;
  51. }
  52.  
  53. /*************************************************************************/
  54.  
  55. void updateLine(int i)
  56. {
  57.     int j, len, n, sel;
  58.     char *s;
  59.  
  60.     s = getTreeLine(getLastNodeInLevel(_rootNode, _y0 + i), _lineart, 1);
  61.     move(i + 1, 2);
  62.     attrset(getColorMode(0));
  63.     hline(' ', _cols - 3);
  64.     sel = 0;
  65.  
  66.     if (s) {
  67.         len = strlen(s);
  68.         n = 2;
  69.         for (j = _x0; j < len; j++) {
  70.             if (n > _cols - 3)
  71.                 break;
  72.             switch (s[j]) {
  73.             case __ACS_HL:
  74.                 addch(ACS_HLINE);
  75.                 break;
  76.             case __ACS_VL:
  77.                 addch(ACS_VLINE);
  78.                 break;
  79.             case __ACS_LT:
  80.                 addch(ACS_LTEE);
  81.                 break;
  82.             case __ACS_LLC:
  83.                 addch(ACS_LLCORNER);
  84.                 break;
  85.             case __ACS_TT:
  86.                 addch(ACS_TTEE);
  87.                 break;
  88.             case __SEL_ON:
  89.                 attrset(getColorMode(1));
  90.                 sel = 1;
  91.                 n--;
  92.                 break;
  93.             case __SEL_OFF:
  94.                 attrset(getColorMode(0));
  95.                 sel = 0;
  96.                 n--;
  97.                 break;
  98.             default:
  99.                 addch(s[j]);
  100.             }
  101.             n++;
  102.         }
  103.         if ((sel) && (s[j] != __SEL_OFF))
  104.             mvaddstr(i + 1, _cols - 5, "...");
  105.     }
  106.     leaveok(stdscr, FALSE);
  107.     attrset(getColorMode(0));
  108. }
  109.  
  110. /*************************************************************************/
  111.  
  112. void dataRefresh(int newx, int newy, DirNode * newNode)
  113. {
  114.     int i, len, y;
  115.     char *s;
  116.     DirNode * oNode;
  117.     int oy;
  118.     
  119.     if (newNode == NULL)
  120.         newNode = _curNode;
  121.  
  122.     if (newy < 0)
  123.         newy = 0;
  124.     if (newy > newNode->y)
  125.         newy = newNode->y;
  126.     if (newNode->y - newy > _lines - 6)
  127.         newy = newNode->y - (_lines - 6);
  128.  
  129.     if (newx >= newNode->x)
  130.         newx = newNode->x - 2;
  131.     if (newx < 0)
  132.         newx = 0;
  133.     len = strlen(getNodeName(newNode, (_showlink?1:-1)));
  134.     if (len > _cols - 4)
  135.         len = _cols - 4;
  136.     if (newNode->x - newx + len > _cols - 4)
  137.         newx = newNode->x + len - (_cols - 4);
  138.  
  139.     len = strlen(_searchPath);
  140.     y = newNode->y - newy;
  141.     
  142.     if ((newx!=_x0)||(newy!=_y0)) {
  143.         _refCurrent = 1;
  144.         _refRest = 1;
  145.     }
  146.     if (_searchPLen!=len)
  147.         _refSearch = 1;
  148.     if ((_curNode!=newNode)||(_curNode->y-_y0!=y)) 
  149.         _refCurrent = 1;
  150.      if (_curNode!=newNode) 
  151.          _refCurDir = 1;
  152.      
  153.     
  154.     oNode = _curNode;
  155.     oy = oNode->y-_y0;
  156.     
  157.     _x0 = newx;
  158.     _y0 = newy;
  159.     _curNode = newNode;
  160.  
  161.     leaveok(stdscr, TRUE);
  162.  
  163.     if (_refSearch) {
  164.         _refSearch = 0;
  165.         _searchPLen = len;
  166.         move(_lines - 2, 10);
  167.         attrset(getColorMode(1));
  168.         if (COLS - 25 > SEARCHWIN_LEN) {
  169.             hline(' ', SEARCHWIN_LEN);
  170.             _searchPX = SEARCHWIN_LEN;
  171.         }
  172.         else {
  173.             hline(' ', COLS - 25);
  174.             _searchPX = COLS - 25;
  175.         }
  176.         if (len < _searchPX) {
  177.             waddstr(stdscr, _searchPath);
  178.             _searchPX = len;
  179.         }
  180.         else {
  181.             _searchPX--;
  182.             waddstr(stdscr, _searchPath + len - _searchPX);
  183.             mvaddstr(_lines - 2, 10, "...");
  184.         }
  185.     }
  186.  
  187.     attrset(getColorMode(0));
  188.  
  189.     if (_refCurrent) {
  190.         _refCurrent = 0;
  191.         updateLine(y);
  192.     }
  193.  
  194.     if (kbHit()) {  
  195.         if (y!=oy)
  196.             _refRest = 1;
  197.         return;
  198.     }
  199.     if (y!=oy)
  200.         updateLine(oy);
  201.  
  202.      if (_refCurDir) {
  203.         if (kbHit())  
  204.             return; 
  205.         _refCurDir = 0;
  206.         s = truncString(getNodeFullPath(newNode, 1, (_scope == -1), NULL, 0), _cols - 4); 
  207.         attrset(getColorMode(0));
  208.         mvaddstr(_lines - 3, 2, s);
  209.         hline(' ', _cols - 4 - strlen(s));
  210.     }
  211.  
  212.     if (_refRest) {
  213.         for (i = 0; i < _lines - 5; i++) { 
  214.             if (kbHit()) 
  215.                 return;
  216.             if ((i != y) && (i != oy))
  217.                 updateLine(i);
  218.     
  219.         }
  220.         _refRest = 0;
  221.     }
  222.     leaveok(stdscr, FALSE);
  223.     move(_lines - 2, 10 + _searchPX);
  224. }
  225.  
  226. /*************************************************************************/
  227.  
  228. void editSearch(int ch)
  229. {
  230.     DirNode * dn;
  231.     int len;
  232.     int be;
  233.  
  234.     be = 0;
  235.     len = strlen(_searchPath);
  236.     dn = _curNode;
  237.  
  238.     if ((ch == 8) || (ch == 127) || (ch == 4)) {
  239.         if (len) {
  240.             _searchPath[len - 1] = 0;
  241.         }
  242.         ch = -1;
  243.     }
  244.     
  245.     if ((ch>0)&&(ch < 32)) {
  246.         be = 1;
  247.     }
  248.     else {
  249.         if (ch) {
  250.             if (ch>0) {
  251.                 _searchPath[len] = ch;
  252.                 _searchPath[len + 1] = '\0';
  253.             }
  254.             dn = findDirInCicle(_rootNode, _curNode, _searchPath); 
  255.         }
  256.         else if (len)
  257.             dn = findDirInCicle(_rootNode, nextNodeCiclic(_rootNode, _curNode), _searchPath);
  258.         else
  259.             dn = NULL;
  260.             
  261.         if (dn==NULL) {
  262.             _searchPath[len] = '\0';
  263.             be = 1;
  264.             dn = _curNode;
  265.         }
  266.     }
  267.  
  268.     dataRefresh(_x0, _y0, dn);
  269. /*
  270.     if (be)
  271.         beep();
  272. */
  273. }
  274.  
  275. /*************************************************************************/
  276.  
  277. void showHelpScreen()
  278. {
  279.     char *title = " HELP ";
  280.     char *msg = 
  281.     "                                                            "
  282.     "     ______________MOVE______________   ____SEARCH_____     "
  283.     "     ^P/Up.........Up  ^A/Home...Home   ^K/F9......Next     "
  284.     "     ^N/Down.....Down  ^E/End.....End   ^H/BSpc...DelCh     "
  285.     "     ^B/Left.....Left  ^U/PgUp...PgUp   ^D/Del....Clear     "
  286.     "     ^F/Right...Right  ^V/PgDn...PgDn   _____LINKS_____     "
  287.     "     ^F/Right....Next  ^O/F7.....LnUp   ^L|F5....Follow     "
  288.     "     ^T..........Prev  ^J/F8.....LnDn   ^G|F6......View     "
  289.     "     ______________MISC______________   _______________     "
  290.     "     ^R/F2.....Rescan  ^Y/F3....Scope   ^M/Return....OK     "
  291.     "     ^W/F4....Repaint  ^I/F1.....Help   ^X/F10.....Quit     "    
  292.     "                                                            "
  293.     "";
  294.     
  295.     WINDOW * w;
  296.     int x, y;
  297.     
  298.     y = (_lines-HLP_LINES)/2;
  299.     x = (_cols-HLP_COLS)/2;
  300.     w = newwin(HLP_LINES,HLP_COLS,y,x);
  301.     
  302.     leaveok(w, TRUE);
  303.     wattrset(w,getColorMode(1));
  304.  
  305.     mvwprintw(w,1,0,"%s",msg);
  306.     box(w,ACS_VLINE,ACS_HLINE);
  307.     mvwprintw(w,HLP_LINES-1,HLP_COLS-30," 1995 (c)  Borja Etxebarria ");
  308.     mvwaddstr(w,0,(HLP_COLS-strlen(title))/2,title);    
  309.  
  310.     wrefresh(w);
  311.     
  312.     delwin(w);
  313.     
  314. }
  315.  
  316. /*************************************************************************/
  317.  
  318. void showHelpNoSpace()
  319. {
  320.     char *msg1 = " This screen is too small ";
  321.     char *msg2 = "  to display help window  ";
  322.     WINDOW * w;
  323.     int x, y;
  324.     
  325.     y = (_lines-4)/2;
  326.     x = (_cols-strlen(msg1)-2)/2;
  327.     w = newwin(4,strlen(msg1)+2,y,x);
  328.  
  329.     leaveok(w, TRUE);    
  330.     wattrset(w,getColorMode(1));
  331.     box(w,ACS_VLINE,ACS_HLINE);
  332.     mvwaddstr(w,1,1,msg1);
  333.     mvwaddstr(w,2,1,msg2);
  334.  
  335.     wrefresh(w);
  336.     
  337.     delwin(w);
  338. }
  339.  
  340. /*************************************************************************/
  341.  
  342. void cursRebuildMsg()
  343. {
  344.     char *msg1 = " Rebuilding directory ";
  345.     char *msg2 = " tree, please wait... ";
  346.     WINDOW * w;
  347.     int x, y;
  348.     
  349.     y = (_lines-4)/2;
  350.     x = (_cols-strlen(msg1)-2)/2;
  351.     w = newwin(4,strlen(msg1)+2,y,x);
  352.  
  353.     leaveok(w, TRUE);    
  354.     wattrset(w,getColorMode(1));
  355.     box(w,ACS_VLINE,ACS_HLINE);
  356.     mvwaddstr(w,1,1,msg1);
  357.     mvwaddstr(w,2,1,msg2);
  358.  
  359.     wrefresh(w);
  360.     
  361.     delwin(w);
  362. }
  363.  
  364. /*************************************************************************/
  365.